package com.jixiantubu.yueban;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import image.SmartImageView;
import com.example.jixiantubu.R;
import com.jixiantubu.bean.Ac_Bean;
import com.jixiantubu.util.MyApplication;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

public class YueBan_XQ_BaoMing extends Activity implements OnClickListener {
	private Ac_Bean ac;
	private Button ac_bm_queding;
	private ImageView ac_bm_back;
	private SmartImageView ac_bm_pic;
	private int ac_id;
	private String rl_number, rl_phone, rl_massage;
	private TextView ac_bm_title, ac_bm_time;
	private EditText ac_people_num, ac_people_phone,
			ac_bm_massage;
	private List<Ac_Bean> list = new ArrayList<Ac_Bean>();
	private String url = "http://" + MyApplication.getIP()
			+ ":8080/Jinnang/YueBan_BaoMing";
	private MyApplication application;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		Window window = this.getWindow();
		window.requestFeature(window.FEATURE_NO_TITLE);
		setContentView(R.layout.ac_baoming);
		initViews();
		initData();
	}

	private void initViews() {
		Intent intent = getIntent();
		ac = (Ac_Bean) intent.getSerializableExtra("ac");
		ac_bm_back = (ImageView) findViewById(R.id.ac_bm_back); 
		ac_bm_queding = (Button) findViewById(R.id.ac_bm_queding);
		ac_bm_pic = (SmartImageView) findViewById(R.id.ac_bm_pic);
		ac_bm_title = (TextView) findViewById(R.id.ac_bm_title);
		ac_bm_time = (TextView) findViewById(R.id.ac_bm_time);
		ac_people_num =  (EditText) findViewById(R.id.ac_people_num);
		ac_people_phone =  (EditText) findViewById(R.id.ac_people_phone);
		ac_bm_massage = (EditText) findViewById(R.id.ac_bm_massage);
		ac_bm_back.setOnClickListener(this);
		ac_bm_queding.setOnClickListener(this);

	}

	private void initData() {
		String resId = "http://" + MyApplication.getIP() + ":8080/Jinnang/img/"
				+ ac.getAc_pic_path();
		ac_bm_pic.setImageUrl(resId);
		System.out.println("具体图片" + resId);
		ac_bm_title.setText(ac.getAc_title());
		ac_bm_time
				.setText("时间：" + ac.getAc_time() + "——" + ac.getAc_lastTime());

	}

	public void upload() {
		RequestParams params = new RequestParams();
		ac_id = ac.getAc_id();
		rl_number = ac_people_num.getText().toString();
		rl_phone = ac_people_phone.getText().toString();
		rl_massage = ac_bm_massage.getText().toString();
		params.addBodyParameter("user_id", MyApplication.user_id);
		params.addBodyParameter("ac_id", String.valueOf(ac_id));
		params.addBodyParameter("rl_number", rl_number);
		params.addBodyParameter("rl_phone", rl_phone);
		params.addBodyParameter("rl_massage ", rl_massage);
		HttpUtils http = new HttpUtils();
		http.send(HttpMethod.POST, url, params, new RequestCallBack<String>() {
			@Override
			public void onFailure(HttpException arg0, String arg1) {

			}

			@Override
			public void onSuccess(ResponseInfo<String> arg0) {
			}
		});
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.ac_bm_back:
			finish();
			break;
		case R.id.ac_bm_queding:
			upload();
			finish();
			/*Intent intent = new Intent(yueban_xq_baoming.this,
					yueban_xiangqing.class);
			startActivity(intent);*/
			break;

		default:
			break;
		}

	}

}
